package demoMod.invincibleOne.effects;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.helpers.MathHelper;
import com.megacrit.cardcrawl.vfx.AbstractGameEffect;
import demoMod.invincibleOne.InvincibleOneMod;
import demoMod.invincibleOne.patches.CharacterSelectPatch;

public class EndCGEffect extends AbstractGameEffect {
    private static Texture back = new Texture(InvincibleOneMod.getResourcePath("char/victoryBack.png"));
    public static Texture[] cgs = new Texture[3];
    private float FadeInOut;
    private final static float cgDuration = 3.5F;

    public EndCGEffect() {
        this.duration = cgDuration * 3.0F;
        this.FadeInOut = 0.2F;
        this.color = new Color(1.0F, 1.0F, 1.0F, 0.0F);
    }

    public void update() {
        if (cgDuration * 3.0F - this.duration < this.FadeInOut) {
            this.color.a = MathHelper.scaleLerpSnap(this.color.a, 1.0F);
        } else if (this.duration < this.FadeInOut) {
            this.color.a = MathHelper.scaleLerpSnap(this.color.a, 0.0F);
        }
        if (this.duration < 0.0F) {
            this.isDone = true;
        } else {
            this.duration -= Gdx.graphics.getDeltaTime();
        }
    }

    public void render(SpriteBatch spriteBatch) {
        spriteBatch.draw(back, 0.0F, 0.0F, back
                .getWidth() * Settings.scale, back
                .getHeight() * Settings.scale);
        if (!this.isDone) {
            for (int i = 0; i < 3; i++) {
                Color temp = spriteBatch.getColor();
                float a = Math.min(1.0F, (3.0F * cgDuration - this.duration) - (float)i * cgDuration);
                spriteBatch.setColor(new Color(1.0F, 1.0F, 1.0F, Math.max(a, 0.0F)));
                Texture t = cgs[i];
                spriteBatch.draw(t, 0.0F, 0.0F, t
                        .getWidth() * Settings.scale, t
                        .getHeight() * Settings.scale);
                spriteBatch.setBlendFunction(770, 771);
                spriteBatch.setColor(temp);
            }
        }
    }

    public void dispose() {
        Settings.hideTopBar = false;
    }
}
